package com.example.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.entity.HeSuan;
import com.example.service.HeSuanService;
import com.example.vo.DataView;
import com.example.vo.HeSuanVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/hesuan")
public class HeSuanController {

    @Autowired
    private HeSuanService heSuanService;

    @RequestMapping("/loadAllHeSuan")
    public DataView loadAllHeSuan(HeSuanVo heSuanVo){
        IPage<HeSuan> page=new Page<>(heSuanVo.getPage(), heSuanVo.getLimit());
        QueryWrapper<HeSuan> queryWrapper=new QueryWrapper<>();
//        queryWrapper.like(StringUtils.isNotBlank(heSuanVo.getTitle()),"title",heSuanVo.getTitle());
//        queryWrapper.orderByAsc("ordernum");
        heSuanService.page(page,queryWrapper);
        return new DataView(page.getTotal(),page.getRecords());
    }

    @RequestMapping({"/addHeSuan","/updateHeSuan"})
    public DataView addHeSuan(HeSuan heSuan){
        heSuanService.saveOrUpdate(heSuan);
        DataView dataView=new DataView();
        dataView.setCode(200);
        dataView.setMsg("操作成功");
        return dataView;
    }

    @RequestMapping("/deleteHeSuan")
    public DataView deleteHeSuan(Integer id){
        heSuanService.removeById(id);
        DataView dataView=new DataView();
        dataView.setCode(200);
        dataView.setMsg("删除成功");
        return dataView;
    }
}
